package com.tanhua.server.server;

import com.tanhua.dubbo.api.OptionApi;
import com.tanhua.dubbo.api.QuestionsApi;
import com.tanhua.dubbo.api.TitleApi;
import com.tanhua.model.domian.Option;
import com.tanhua.model.domian.Questions;
import com.tanhua.model.domian.Title;
import com.tanhua.model.vo.OptionVo;
import com.tanhua.model.vo.SoulVo;
import com.tanhua.model.vo.TitleVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TestSoulService {

    @DubboReference
    private QuestionsApi questionsApi;
    @DubboReference
    private TitleApi titleApi;
    @DubboReference
    private OptionApi optionApi;

    /**
     * 灵魂题目列表
     * @return
     */
    public List<SoulVo> SoulList() {
        //拿到灵魂大题
        List<Questions> questionsList =  questionsApi.queryQuestion();
        //拿到小题
        List<Title> titleList = titleApi.queryTitle();
        //拿到小题选项
        List<Option> optionList = optionApi.queryOption();

        List<SoulVo> soulVos = new ArrayList<>();
        for (Questions questions : questionsList) {
            SoulVo init = SoulVo.init(questions);
            List<TitleVo> titleVos = new ArrayList<>();
            for (Title title : titleList) {
                if (title.getQuestionsTitle() == questions.getId()) {
                    TitleVo init1 = TitleVo.init(title);
                    List<OptionVo> optionVos = new ArrayList<>();
                    for (Option option : optionList) {
                        if (option.getOptionTitle() == title.getId()) {
                            OptionVo init2 = OptionVo.init(option);
                            optionVos.add(init2);
                        }
                    }
                    init1.setOptions(optionVos);
                    titleVos.add(init1);
                }
            }
            init.setQuestions(titleVos);
            soulVos.add(init);
        }
        return soulVos;
    }
}
